﻿using System;
using System.Runtime.Serialization;
using ApplicationLibrary.ExtendedControls;

namespace ApplicationLibrary.Preferences
{
    public partial class GlobalPreferencePanel : GlobalPreferencePanelNoVis
    {
        private EnumsManager<Languages> languageManager;

        public GlobalPreferencePanel(string appName)
            : base(appName)
        {
            InitializeComponent();
            ButtonText = Properties.Resources.T_GlobalPref;
            ButtonImage = Properties.Resources.Gear;
            languageManager = new EnumsManager<Languages>(cbbLanguages, Properties.Resources.ResourceManager);
        }

        public GlobalPreferencePanel()
        {
            InitializeComponent();
            ButtonText = Properties.Resources.T_GlobalPref;
            ButtonImage = Properties.Resources.Email;
            languageManager = new EnumsManager<Languages>(cbbLanguages, Properties.Resources.ResourceManager);
        }

        protected override void OnBindData()
        {
            BindControl(cbbLanguages, "Language", "SelectedValue");
            BindControl(ckbForceLanguage, "ForceLanguage", "Checked");
            BindControl(ckbExpandSearch, "ExpandSearchWindow", "Checked");
            BindControl(ckbModalWindows, "ModalWindow", "Checked");
            BindControl(ckbColors, "CustmColor", "Checked");
            BindControl(ckbUseTransaction, "UseTransaction", "Checked");
        }

        protected override void OnDisableControlsForEdit()
        {
            cbbLanguages.Enabled = ckbForceLanguage.Checked;
        }

        protected override void OnDisableControlsForNew()
        {
            cbbLanguages.Enabled = ckbForceLanguage.Checked;
        }

        private void ckbForceLanguage_CheckedChanged(object sender, EventArgs e)
        {
            cbbLanguages.Enabled = ckbForceLanguage.Checked;
        }
    }

    #region MailPreferencePanelNoVis

    public partial class GlobalPreferencePanelNoVis : ApplicationLibrary.Preferences.GenericPreferencePanel<GlobalPref>
    {
        public GlobalPreferencePanelNoVis(string appName)
            : base(appName, null)
        {
        }

        public GlobalPreferencePanelNoVis()
        {
        }
    }

    #endregion

    [DataContract]
    public class GlobalPref
    {
        [DataMember]
        public bool ExpandSearchWindow { get; set; }

        [DataMember]
        public bool ModalWindow { get; set; }

        [DataMember]
        public bool ForceLanguage { get; set; }

        [DataMember]
        public int Language { get; set; }

        [DataMember]
        public bool CustmColor { get; set; }

        [DataMember]
        public bool UseTransaction { get; set; }

        public GlobalPref()
        {
        }
    }
}